﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zocono.WCS.Domain.PlcBytesObject
{
    public class ZJNScMessageWcsActionBO : BytesObjectBase
    {
        /// <summary>
        /// 启动命令
        /// </summary>
        public bool Startcommand { get; set; }
        /// <summary>
        /// 报警复位
        /// </summary>
        public bool Alarmreset { get; set; }
        /// <summary>
        /// 自动任务复位
        /// </summary>
        public bool Taskreset { get; set; }
        /// <summary>
        /// WCS消防命令
        /// </summary>
        public bool WCSfirecommand { get; set; }

        /// <summary>
        /// WCS拍照温度无异常
        /// </summary>
        public bool WCSPhotoFire { get; set; }

        /// <summary>
        /// WCS拍照温度异常堆垛机救火
        /// </summary>
        public bool WCSRgvFireHlper { get; set; }

        /// <summary>
        /// DTS有温度报警但红外摄像仪拍照无异常，请人工检查
        /// </summary>
        public bool WCSDTSAlarm { get; set; }

        /// <summary>
        /// WCS时间复位
        /// </summary>
        public bool TimeReset { get; set; }
        /// <summary>
        /// 工作序号
        /// </summary>
        public int Jobnumber { get; set; }
        /// <summary>
        /// 工作命令代码
        /// </summary>
        public short Jobordercode { get; set; }
        /// <summary>
        /// 启始行fromPC
        /// </summary>
        public short StartlinefromPC { get; set; }
        /// <summary>
        /// 启始列fromPC
        /// </summary>
        public short StartcolumnfromPC { get; set; }
        /// <summary>
        /// 启始层fromPC
        /// </summary>
        public short StartlayerfromPC { get; set; }
        /// <summary>
        /// 目标行fromPC
        /// </summary>
        public short TargetlinefromPC { get; set; }
        /// <summary>
        /// 目标列fromPC
        /// </summary>
        public short TargetcolumnfromPC { get; set; }
        /// <summary>
        /// 目标层fromPC
        /// </summary>
        public short TargetlayerfromPC { get; set; }
        /// <summary>
        /// WCS过账完成
        /// </summary>
        public short WCSpostingcompleted { get; set; }
        /// <summary>
        /// 手动任务复位
        /// </summary>
        public short yuliu8 { get; set; }
        public short yuliu9 { get; set; }
        public short yuliu10 { get; set; }
        public short yuliu11 { get; set; }
        public short yuliu12 { get; set; }

        public override void Serialize(long plcConnectionID, long plcReadDbID, int bytesIndex, int bytesLength, int objectIndex, int objectLength, string objectType, string ScEquipmentCode, byte[] bytes)
        {
            PlcConnectionID = plcConnectionID;
            PlcReadDbID = plcReadDbID;
            BytesIndex = bytesIndex;
            BytesLength = bytesLength;
            ObjectIndex = objectIndex;
            ObjectLength = objectLength;
            /// <summary>
            /// 约定：
            /// 1、设备状态报文以State结尾；
            /// 2、Plc的动作报文以PlcAction结尾；
            /// 3、Wcs的动作报文以WcsAction结尾；
            /// 4、平面PLC报文统一PlcState名称
            /// （后续有其他的再约定）
            /// </summary>
            ObjectType = objectType;
            EquipmentCode = ScEquipmentCode;

            Startcommand = HelperByte.GetBitAt(bytes, 0, 0);
            Alarmreset = HelperByte.GetBitAt(bytes, 0, 1);
            Taskreset = HelperByte.GetBitAt(bytes, 0, 2);
            WCSfirecommand = HelperByte.GetBitAt(bytes, 0, 3);
            WCSPhotoFire = HelperByte.GetBitAt(bytes, 0, 4);
            WCSRgvFireHlper = HelperByte.GetBitAt(bytes, 0, 5);
            WCSDTSAlarm = HelperByte.GetBitAt(bytes, 0, 6);
            TimeReset = HelperByte.GetBitAt(bytes, 0, 7);

            Jobnumber = HelperByte.GetDIntAt(bytes, 2);
            Jobordercode = HelperByte.GetIntAt(bytes, 6);
            StartlinefromPC = HelperByte.GetIntAt(bytes, 8);
            StartcolumnfromPC = HelperByte.GetIntAt(bytes, 10);
            StartlayerfromPC = HelperByte.GetIntAt(bytes, 12);
            TargetlinefromPC = HelperByte.GetIntAt(bytes, 14);
            TargetcolumnfromPC = HelperByte.GetIntAt(bytes, 16);
            TargetlayerfromPC = HelperByte.GetIntAt(bytes, 18);
            WCSpostingcompleted = HelperByte.GetIntAt(bytes, 20);
            yuliu8 = HelperByte.GetIntAt(bytes, 22);
            yuliu9 = HelperByte.GetIntAt(bytes, 24);
            yuliu10 = HelperByte.GetIntAt(bytes, 26);
            yuliu11 = HelperByte.GetIntAt(bytes, 28);
            yuliu12 = HelperByte.GetIntAt(bytes, 30);
        }

        //public override byte[] Derialize()
        //{
        //    byte[] bytes = new byte[32];
        //    HelperByte.SetBitAt(ref bytes, 0, 0, Startcommand);
        //    HelperByte.SetBitAt(ref bytes, 0, 1, Alarmreset);
        //    HelperByte.SetBitAt(ref bytes, 0, 2, Taskreset);
        //    HelperByte.SetBitAt(ref bytes, 0, 3, WCSfirecommand);
        //    HelperByte.SetDIntAt(bytes, 2, Jobnumber);
        //    HelperByte.SetIntAt(bytes, 6, Jobordercode);
        //    HelperByte.SetIntAt(bytes, 8, StartlinefromPC);
        //    HelperByte.SetIntAt(bytes, 10, StartcolumnfromPC);
        //    HelperByte.SetIntAt(bytes, 12, StartlayerfromPC);
        //    HelperByte.SetIntAt(bytes, 14, TargetlinefromPC);
        //    HelperByte.SetIntAt(bytes, 16, TargetcolumnfromPC);
        //    HelperByte.SetIntAt(bytes, 18, TargetlayerfromPC);
        //    HelperByte.SetIntAt(bytes, 20, WCSpostingcompleted);
        //    HelperByte.SetIntAt(bytes, 22, yuliu8);
        //    HelperByte.SetIntAt(bytes, 24, yuliu9);
        //    HelperByte.SetIntAt(bytes, 26, yuliu10);
        //    HelperByte.SetIntAt(bytes, 28, yuliu11);
        //    HelperByte.SetIntAt(bytes, 30, yuliu12);
        //    return bytes;
        //}


    }
}
